export default function ({ store, route, redirect }) {
  const lang = store.state.lang

  if (lang) {
    store.commit('update', {
      lang,
    })
  }

  const routePath = route.path
  if (store.state.lang === 'zh' && !routePath.includes(`/${store.state.lang}`)) {
    return redirect({ path: `/${store.state.lang}${routePath}`, query: route.query })
  }
  if (store.state.lang === 'en' && routePath.includes('zh')) {
    const replacePath = routePath.replace('/zh', '') || '/'
    return redirect({ path: replacePath, query: route.query })
  }
}
